<template>
	<view class="page">
		<view style="margin: 10px 0;">
			<el-alert title=" 阿里云OSS配置, 默认情况下无需填写(此处影响很大,填写前请务必咨询技术人员)" type="success" :closable="true">
			</el-alert>
		</view>
		<view class="formview">
			<vk-data-form ref="form1" v-model="form1.data" :action="form1.props.action" :columns="form1.props.columns"
				:rules="form1.props.rules" :form-type="form1.props.formType" :loading.sync="form1.props.loading"
				:auto-close="true" :show-cancel="false" submit-text="提交修改" label-width="160px" @success="onFormSuccess">
			</vk-data-form>
		</view>

	</view>
</template>

<script>
	var that; // 当前页面对象
	var vk = uni.vk; // vk实例
	const db = uniCloud.database();

	export default {
		data() {
			return {
				activeName: 'first',
				// 表单相关开始-----------------------------------------------------------
				form1: {
					// 表单请求数据，此处可以设置默认值
					data: {
						region: "",
						accessKeyId: "",
						accessKeySecret: "",
						bucket: "",
						baseurl: ""
					},
					// 表单属性
					props: {
						// 表单请求地址
						action: "admin/system/alioss/kh/alioss",
						// 表单字段显示规则
						columns: [{
								"key": "region",
								"title": "region",
								"type": "text",
								"tips": "如：oss-cn-hangzhou"
							},
							{
								"key": "accessKeyId",
								"title": "accessKeyId",
								"type": "text"
							},
							{
								"key": "accessKeySecret",
								"title": "accessKeySecret",
								"type": "text"
							},
							{
								"key": "bucket",
								"title": "bucket",
								"type": "text",
								"tips": "如：hddj2022"
							},
							{
								"key": "baseurl",
								"title": "baseurl",
								"type": "text",
								"tips": "如：https://hddj2022.oss-cn-hangzhou.****yun.com/"
							},

						],
						// 表单验证规则
						rules: {

						},
						// add 代表添加 update 代表修改
						formType: "update",
						// 表单是否在请求中
						loading: false,
						// 是否显示表单1 的弹窗
						show: false
					}
				},
				// 表单相关结束-----------------------------------------------------------
			};
		},
		// 监听 - 页面每次【加载时】执行(如：前进)
		onLoad(options = {}) {
			that = this;
			vk = that.vk;
			that.options = options;
		},
		async onShow() {
			if (vk.vuex.get('$user.userInfo.username') != "admin") {
				uni.redirectTo({
					url: "/pages/index/index"
				})
				return;
			}
			this.loadData()
		},
		onReady() {

		},
		methods: {
			handleClick(tab, event) {
				console.log(tab, event);
			},
			async loadData() {
				const alioss = await db.collection('a_config').where({
					name: "alioss"
				}).get()
				if (alioss.result.data[0]) {
					this.form1.data = alioss.result.data[0];
				}
			},
			onFormSuccess() {
				this.loadData()
			}
		}
	};
</script>

<style>
	.page {
		padding-top: 20px;
	}

	.formview {
		width: 60%;
	}
</style>
